package cn.thoughtworks.school.repositories;

import cn.thoughtworks.school.entities.Task;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface TaskDiffRepository extends JpaRepository<Task, Long> {

    @Query(value = "select * from task where id in (\n" +
        "select max(id) from task t where\n" +
        "t.topicId in ?1 group by topicId,taskId order by taskId desc\n" +
        ") and operation != 2",nativeQuery = true)
    List<Task> findFirst1ByIdAndProgramIdInOrderByTopicsIdDesc(List<Long> topicsId);

    Task findFirst1ByTaskIdOrderByIdDesc(Long taskId);

    List<Task> findAllByTaskIdOrderByIdDesc(Long taskId);
}
